package com.machine.filling.function.init.InputOilGunInfo;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.machine.filling.R;
import com.machine.filling.net.http.response.OilTypeListResBean;

import java.util.List;

/**
 * Created by Administrator on 2018/2/19 0019.
 */

public class OilTypesAdapter extends RecyclerView.Adapter<OilTypesAdapter.Holder> {

    private Context mContext;
    private List<OilTypeListResBean.ResultBean.TypesBean> datas;

    public OilTypesAdapter(Context mContext, List<OilTypeListResBean.ResultBean.TypesBean> datas) {
        this.mContext = mContext;
        this.datas = datas;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_oil_type, parent, false);
        return new Holder(view);
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        holder.tv_name.setText(datas.get(position).getShortName() + "[" + datas.get(position).getNum() + "]");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClick(datas.get(position),position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class Holder extends RecyclerView.ViewHolder {

        private final TextView tv_name;

        public Holder(View itemView) {
            super(itemView);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
        }
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener{
        void onItemClick(OilTypeListResBean.ResultBean.TypesBean itemBean,int position);
    }
}
